package com.seele.tigerwallet.ui.adapter;

import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seele.tigerwallet.R;
import com.seele.tigerwallet.model.TsModel;
import com.seele.tigerwallet.model.UserInfo;
import com.seele.tigerwallet.ui.application.SeeleApplication;
import com.seele.tigerwallet.utils.Utils;
import com.seele.tigerwallet.wallet.WalletManager;

public class TokenIntercourseAdapter extends BaseQuickAdapter<TsModel, BaseViewHolder> {


    public TokenIntercourseAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, TsModel item) {
        if (item.tsfromaddr.equalsIgnoreCase(UserInfo.get().address)) { //转出
            helper.setImageResource(R.id.token_icon_img, R.drawable.transferout);
            helper.setText(R.id.count_tv, "-" + item.value);
            helper.setText(R.id.count_symbol, item.symbol);
            helper.setText(R.id.token_address_tv, item.tstoaddr);
        } else { // 转入
            helper.setImageResource(R.id.token_icon_img, R.drawable.transferin);
            helper.setText(R.id.count_tv, "+" + item.value);
            helper.setText(R.id.count_symbol, item.symbol);
            helper.setText(R.id.token_address_tv, item.tsfromaddr);
        }

        TextView textView = helper.getView(R.id.token_address_tv);
        TextView textViewTime = helper.getView(R.id.time_tv);
        //Typeface font = Typeface.createFromAsset(SeeleApplication.getInstance().getAssets(), "fonts/CENTURY_GOTHIC_BOLD.TTF");
        //textView.setTypeface(font);
        //textViewTime.setTypeface(font);
        String formatTime = Utils.formatTransferTime(item.tstime);
        helper.setText(R.id.time_tv, formatTime);


        //helper.setText(R.id.pb_progress_bar, )
        int acknum = Integer.valueOf(item.tsacknum).intValue();
        int progress = acknum * 100 / 12;
        ProgressBar progressBar = helper.getView(R.id.pb_progress_bar);
        View view = helper.getView(R.id.view_spit);
        progressBar.setVisibility(View.GONE);
        view.setVisibility(View.VISIBLE);
        if (item.tsstatus == 0) {
            helper.setText(R.id.progress_tv, mContext.getString(R.string.transfer_failed));
            helper.setTextColor(R.id.progress_tv, SeeleApplication.getInstance().getResources().getColor(R.color.color_E87075));
        }
        else if (item.tsstatus == 1) {
            helper.setText(R.id.progress_tv, "");
        } else if (item.tsstatus == 2) { //暂时没用
            //helper.setText(R.id.progress_tv, mContext.getResources().getString(R.string.transfer_pedding));
        } else if (item.tsstatus == 3) {
            helper.setText(R.id.progress_tv, mContext.getString(R.string.transfer_pendding));
            helper.setTextColor(R.id.progress_tv, SeeleApplication.getInstance().getResources().getColor(R.color.color_C0C0C0));
        } else if (item.tsstatus == 4) {
            helper.setText(R.id.progress_tv, mContext.getString(R.string.transfer_penddingfailed));
            helper.setTextColor(R.id.progress_tv, SeeleApplication.getInstance().getResources().getColor(R.color.color_E87075));
        } else if (item.tsstatus == 5) {
            view.setVisibility(View.GONE);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(progress);
            helper.setText(R.id.progress_tv, String.format("%s:%s/12", mContext.getString(R.string.transfer_confirming),item.tsacknum));
            helper.setTextColor(R.id.progress_tv, SeeleApplication.getInstance().getResources().getColor(R.color.color_63D0AB));
        }

//
//        if (acknum >= 12 ) {
//            //RelativeLayout.LayoutParams linearParams =(android.widget.RelativeLayout.LayoutParams) progressBar.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
//            //linearParams.height = 2;
//            //progressBar.setLayoutParams(linearParams);
//            progressBar.setProgress(0);
//            helper.setText(R.id.progress_tv, "");
//        } else {
//            progressBar.setProgress(progress);
//            helper.setText(R.id.progress_tv, String.format("确认数:%s/12",item.tsacknum));
//        }

    }
}
